<template>
  <div id="main" :class="className" :style="{height:height,width:width}" @click="dataZoom(a)"/>
</template>

<script>
import echarts from 'echarts'
require('echarts/theme/macarons') // echarts theme
import resize from './mixins/resize'

export default {
  mixins: [resize],
  props: {
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '232px'
    },
    autoResize: {
      type: Boolean,
      default: true
    },
    chartData: {
      type: Object,
      required: true
    },
  },
  data() {
    return {
      chart: null
    }
  },
  watch: {
    chartData: {
      deep: true,
      handler(val) {
        this.setOptions(val)
      }
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.initChart()
    })
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
 
    
    initChart() {
      this.chart = echarts.init(this.$el, 'macarons')
      this.setOptions(this.chartData)
    },
    setOptions() {
 
      this.chart.setOption({
        xAxis: {
          data: [],
          boundaryGap: false,
          axisTick: {
            show: false
          }
        },
        grid: {
          left: 10,
          right: 10,
          bottom: 20,
          top: 30,
          containLabel: true
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'cross'
          },
          padding: [5, 10]
        },
        yAxis: {
          axisTick: {
            show: false
          }
        },
        legend: {
          textStyle:{
                fontSize: 14,//字体大小
                color: '#82e6ff'//字体颜色
           },
           text: "倾角传感器",
          data: ['X', 'Y','Z'],
        },
        series: [{
          name: 'X', 
          smooth: true,
          type: 'line',
          data: [8948,4848,84,849,65,689,84,969,95,489,465,696,49,649,496,949,48,99,9496,94,64,4589,949,49,94,9,646,64,6,49,,94,9,4,9,49,6,4,9,9,49,4,848,9489,89,49,4,5498,89,48,9,4,894,984,894,89,4,894,8],
          animationDuration: 2800,
          animationEasing: 'cubicInOut'
        },
        {
          name: 'Y',
          smooth: true,
          type: 'line',
          data:[54,487,87,887,889,9,494,84,87,69,966,494,489,59,4969,84,84,84,886,868,451,556,13,454,135,4562,564,321,56,51,894,3456,894,5464,648,6364,6658,47],
          animationDuration: 2800,
          animationEasing: 'quadraticOut'
        },
          {
            name: 'Z',
            smooth: true,
            type: 'line',
          
            data: [151,444,4,648,64,58,6486,646,584,6598,389,689,948,45,45,549,99,89,898,4,9,498,994,99,859,9,49,449,494,94,949,49,49,49,49,],
            animationDuration: 2800,
            animationEasing: 'quadraticOut'
          }]
      })
    },
  }
}
</script>